<template>
  <BoTable
    :columns="columns"
    :request="getHealthConfigList"
    ref="tableRef"
    row-key="id"
    show-index
  >
  </BoTable>
  <FormModal :columns="item"> </FormModal>

  <Modal
    v-model:open="visible"
    :footer="false"
    :destroyOnClose="true"
    wrapClassName="view_modal"
  >
    <TrendChart :state="state"></TrendChart>
  </Modal>
</template>
<route lang="json">
{
  "name": "shake-assess-config",
  "meta": {
    "title": "震动健康评估配置"
  }
}
</route>
<script setup lang="tsx">
import { computed, ref } from 'vue';
import { getDeviceModelSelect } from '@/api';
import { deviceEnum } from '@/constants';
import { useFormModal } from '@boeyo/hooks';
import { useDicts } from '@boeyo/portal';
import { listToEnum } from '@boeyo/shared';
import { BoFormProps, BoTable, BoTableProps } from '@boeyo/ui';
import { Modal } from 'ant-design-vue';
import { getHealthConfigList, updateHealthConfigList } from './api';
import TrendChart from './components/TrendChart.vue';

const tableRef = ref();
const dictArr = ['health_assess', 'device_type', 'point_type', 'link_type'];

const { healthAssessEnum, deviceTypeEnum, pointTypeEnum, linkTypeEnum } =
  useDicts(dictArr);

const deviceModelEnum = ref();
const init = async () => {
  const { data } = await getDeviceModelSelect({ type: deviceEnum.SEISMOGRAPH });
  deviceModelEnum.value = listToEnum(data, 'model', 'modelId');
};
init();

const columns = computed<BoTableProps['columns']>(() => [
  {
    title: '测点名称',
    dataIndex: 'pointName',
  },
  {
    title: '测点类型',
    dataIndex: 'pointType',
    valueEnum: pointTypeEnum.value,
    valueType: 'select',
  },
  {
    title: '所属监测阵',
    dataIndex: 'structureName',
  },
  {
    title: '接入类型',
    dataIndex: 'linkType',
    valueEnum: linkTypeEnum.value,
    hideInSearch: true,
  },
  {
    title: '设备名称',
    dataIndex: 'stationId',
    hideInSearch: true,
  },
  {
    title: '设备类型',
    dataIndex: 'deviceType',
    valueEnum: deviceTypeEnum.value,
    hideInSearch: true,
  },
  {
    title: '设备型号',
    dataIndex: 'modelId',
    valueEnum: deviceModelEnum.value,
    hideInSearch: true,
  },
  {
    title: '加速度EIZ',
    dataIndex: 'accelerationEizStatus',
    valueEnum: healthAssessEnum.value,
    hideInSearch: true,
    valueType: 'status',
  },
  {
    title: '加速度EIN',
    dataIndex: 'accelerationEinStatus',
    hideInSearch: true,
    valueEnum: healthAssessEnum.value,
    valueType: 'status',
  },
  {
    title: '加速度EIE',
    dataIndex: 'accelerationEieStatus',
    hideInSearch: true,
    valueEnum: healthAssessEnum.value,
    valueType: 'status',
  },
  {
    title: '仿真速度EIZ',
    dataIndex: 'speedEizStatus',
    hideInSearch: true,
    valueEnum: healthAssessEnum.value,
    valueType: 'status',
  },
  {
    title: '仿真速度EIN',
    dataIndex: 'speedEinStatus',
    hideInSearch: true,
    valueEnum: healthAssessEnum.value,
    valueType: 'status',
  },
  {
    title: '仿真速度EIE',
    dataIndex: 'speedEieStatus',
    hideInSearch: true,
    valueEnum: healthAssessEnum.value,
    valueType: 'status',
  },
  {
    title: '仿真位移EIZ',
    dataIndex: 'displacementEizStatus',
    hideInSearch: true,
    valueEnum: healthAssessEnum.value,
    valueType: 'status',
  },
  {
    title: '仿真位移EIN',
    dataIndex: 'displacementEinStatus',
    hideInSearch: true,
    valueEnum: healthAssessEnum.value,
    valueType: 'status',
  },
  {
    title: '仿真位移EIE',
    dataIndex: 'displacementEieStatus',
    hideInSearch: true,
    valueEnum: healthAssessEnum.value,
    valueType: 'status',
  },

  {
    title: '操作',
    dataIndex: 'operation',
    hideInSearch: true,
    fixed: 'right',
    actions: [
      {
        text: '配置',
        onClick(record) {
          onConfig(record);
        },
      },
      {
        text: '趋势图',
        onClick(record) {
          onTrendChart(record);
        },
      },
    ],
  },
]);

const item = computed<BoFormProps['columns']>(() => [
  {
    title: '加速度EIZ',
    dataIndex: 'accelerationEiz',
    valueType: 'inputNumber',
    formItemProps: {
      rules: [
        {
          required: true,
          message: '请输入加速度EIZ',
          trigger: 'blur',
        },
      ],
    },
    fieldProps: {
      placeholder: '请输入加速度EIZ',
    },
  },
  {
    title: '加速度EIN',
    dataIndex: 'accelerationEin',
    valueType: 'inputNumber',
    formItemProps: {
      rules: [
        {
          required: true,
          message: '请输入加速度EIN',
          trigger: 'blur',
        },
      ],
    },
    fieldProps: {
      placeholder: '请输入加速度EIN',
    },
  },
  {
    title: '加速度EIE',
    dataIndex: 'accelerationEie',
    valueType: 'inputNumber',
    formItemProps: {
      rules: [
        {
          required: true,
          message: '请输入加速度EIE',
          trigger: 'blur',
        },
      ],
    },
    fieldProps: {
      placeholder: '请输入加速度EIE',
    },
  },
  {
    title: '仿真速度EIZ',
    dataIndex: 'speedEiz',
    valueType: 'inputNumber',
    formItemProps: {
      rules: [
        {
          required: true,
          message: '请输入仿真速度EIN',
          trigger: 'blur',
        },
      ],
    },
    fieldProps: {
      placeholder: '请输入仿真速度EIN',
    },
  },
  {
    title: '仿真速度EIN',
    dataIndex: 'speedEin',
    valueType: 'inputNumber',
    formItemProps: {
      rules: [
        {
          required: true,
          message: '请输入仿真速度EIN',
          trigger: 'blur',
        },
      ],
    },
    fieldProps: {
      placeholder: '请输入加速度EIZ',
    },
  },
  {
    title: '仿真速度EIE',
    dataIndex: 'speedEie',
    valueType: 'inputNumber',
    formItemProps: {
      rules: [
        {
          required: true,
          message: '请输入仿真速度EIE',
          trigger: 'blur',
        },
      ],
    },
    fieldProps: {
      placeholder: '请输入加速度EIZ',
    },
  },
  {
    title: '仿真位移EIZ',
    dataIndex: 'displacementEiz',
    valueType: 'inputNumber',
    formItemProps: {
      rules: [
        {
          required: true,
          message: '请输入仿真位移EIZ',
          trigger: 'blur',
        },
      ],
    },
    fieldProps: {
      placeholder: '请输入仿真位移EIZ',
    },
  },
  {
    title: '仿真位移EIN',
    dataIndex: 'displacementEin',
    valueType: 'inputNumber',
    formItemProps: {
      rules: [
        {
          required: true,
          message: '请输入仿真位移EIN',
          trigger: 'blur',
        },
      ],
    },
    fieldProps: {
      placeholder: '请输入仿真位移EIN',
    },
  },
  {
    title: '仿真位移EIE',
    dataIndex: 'displacementEie',
    valueType: 'inputNumber',
    formItemProps: {
      rules: [
        {
          required: true,
          message: '请输入仿真位移EIE',
          trigger: 'blur',
        },
      ],
    },
    fieldProps: {
      placeholder: '请输入仿真位移EIE',
    },
  },
]);

const { FormModal, open } = useFormModal({
  size: 'small',
  column: 1,
});

const onConfig = (record: any) => {
  open({
    title: '阈值配置',
    request: async (params: any) => {
      await updateHealthConfigList(params);
      tableRef.value.refresh();
    },
    defaultValue: {
      ...record,
    },
  });
};
const visible = ref(false);
const state = ref({});
const onTrendChart = (record: any) => {
  visible.value = true;
  state.value = record;
};
</script>

<style lang="scss" scoped></style>
